package com.fdb.efp.nls.service.impl;

import com.alibaba.fastjson.JSON;
import com.fdb.basic.framework.core.util.TimeUtil;
import com.fdb.efp.nls.common.ConsoleConstant;
import com.fdb.efp.flow.common.vo.PageApproveVO;
import com.fdb.efp.nls.service.dao.MonReliefAppDao;
import com.fdb.efp.nls.service.domain.MonReliefApp;
import com.fdb.efp.nls.service.facade.MonReliefApprDealService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * 需求编号【2019D0509】
 * 息费减免审批通过处理类
 * @author qiuyf
 * @version 0.1 初始为0.1,后续变更则修改
 * @since 2019/11/14 12:31
 */
@Service("flowMonReliefApprDealService")
public class MonReliefApprDealServiceImpl implements MonReliefApprDealService {

    private static Logger logger = LoggerFactory.getLogger(MonReliefApprDealServiceImpl.class);

    @Autowired
    private MonReliefAppDao monReliefAppDao;

    @Override
    public void pass(String bizSerno, PageApproveVO pageApproveVo) {
        logger.debug("======>息费减免申请审批通过逻辑后处理开始，息费减免申请流水号为：" + bizSerno + "<======");
        logger.info("息费减免申请审批通过，审批意见为:" + JSON.toJSONString(pageApproveVo));
        logger.debug("======>息费减免申请审批通过逻辑后处理结束，息费减免申请流水号为：" + bizSerno + "<======");
    }

    @Override
    public void refuse(String bizSerno, PageApproveVO pageApproveVo) {

    }

    @Override
    public void repulse(String bizSerno, PageApproveVO pageApproveVo) {
        logger.debug("======>息费减免申请审批打回逻辑后处理开始，息费减免申请流水号为：" + bizSerno + "<======");
        logger.info("息费减免申请审批打回，审批意见为:" + JSON.toJSONString(pageApproveVo));
        MonReliefApp monReliefApp = new MonReliefApp();
        monReliefApp.setReliefAppNo(bizSerno);
        monReliefApp = monReliefAppDao.queryByPk(monReliefApp);
        if (Objects.isNull(monReliefApp)) {
            logger.error("根据息费减免申请流水号:" + bizSerno + ",获取到的息费减免申请信息为空！");
            return;
        }
        monReliefApp.setApproveStatus(ConsoleConstant.APRV_STATUS_05);
        monReliefApp.setAprvUserCode(pageApproveVo.getAprvUserId());
        monReliefApp.setAprvComment(pageApproveVo.getAprvComment());
        monReliefApp.setAprvTime(TimeUtil.getCurrentDateTime());
        monReliefApp.setLastChgUsr(pageApproveVo.getAprvUserId());
        monReliefAppDao.updateByPk(monReliefApp);
        logger.debug("======>息费减免申请审批打回逻辑后处理结束，息费减免申请流水号为：" + bizSerno + "<======");
        return;
    }
}
